<template>
<div class="tab-bar-item" @click="ItemClick">
  <div v-if="!isActive">
    <slot name="item-icon"></slot>
  </div>
  <div v-else>
    <slot name="item-icon1"></slot>
  </div>
  <!-- 通过计算属性来动态的加载字体颜色 -->
  <div :style="activeColorstyle">
    <slot name="item-text"></slot>
  </div>
</div>
  
</template>

<script>
export default {
  name: "TabBarItem",
  // 通过动态绑定来动态的切换路径、字体颜色
  props: {
    path: String,
    activeColor: {
      type: String,
      default: 'red'
    }
  },
  data(){
    return {

    }
  },
   computed: {
         isActive(){
                return this.$route.path.indexOf(this.path) !== -1
        },
        activeColorstyle(){
            return this.isActive ? {color: this.activeColor}: {}
        }
    },
    methods: {
        ItemClick() {
            this.$router.replace(this.path)
    }
  }
}
</script>

<style scoped>
.tab-bar-item {
  /*弹性大小 */
  flex: 1;
  text-align: center;
  height: 49px;
  font-size: 14px;
}
.tab-bar-item img {
  width: 25px;
  height: 25px;    
  vertical-align: middle;
}
</style>